<?php

declare(strict_types=1);

/**
 *​
 * HomeController.php
 *
 * User：Abell
 * Date：2020/4/14
 * Time：13:20
 * 前缀重写注解路由的使用
 */

namespace App\Controller\Home;

use App\Controller\BaseController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
//引用对应的命名空间
use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;

/**
 * @Controller()
 */
class UserController extends BaseController
{
    /**
     * 用户中心
     * @RequestMapping(path="index", methods="get,post")
     */
    public function index(RequestInterface $request)
    {
        // 从请求中获得 id 参数
        $id = $request->input('id', 1);
        return (string)$id;
    }

    /**
     * 验证码获取 普通图片数字验证码 直接使用ok
     * @RequestMapping(path="vcode", methods="get,post")
     */
    public function vcode(){
        // Will build phrases of 5 characters, only digits
        $phraseBuilder = new PhraseBuilder(4, '0123456789');
        // // Pass it as first argument of CaptchaBuilder, passing it the phrase
        // // builder
        $builder = new CaptchaBuilder(null, $phraseBuilder);
        $builder->build(150, 40);
        $content = $builder->get();
        return $content;
    }
}